﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using AzureDiagMon.Common;
using AzureDiagMon.DB.SqlCE4;
using AzureDiagMon.DB.SqlServer;
using AzureDiagMon.Model;
using Ninject.Modules;

namespace AzureDiagMon.WPFHost
{
    public class Module : NinjectModule
    {
        #region Overrides of NinjectModule

        public override void Load()
        {
            IoC.RegisterModule(typeof(IModelsContainer));
            IoC.RegisterModule(typeof(Services.DataStoreService));
            IoC.RegisterModule(typeof(Views.Main));
            IoC.RegisterModule(typeof(ViewModels.MainViewModel));
            IoC.RegisterModule(typeof(Common.Helpers.WpfHelper));

            IoC.RegisterModule(typeof(SqlCe4DatabaseLayer));
            IoC.RegisterModule(typeof(SqlServerDatabaseLayer));

            try
            {
                var database = DatabaseLayer.Common.DatabaseLayer.SelectDatabaseLayerByConnectionString();
                database.Init();
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("Database initialization failed.\r\n\r\nTechnical details:\r\n{0}", ex),
                                "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Application.Current.Shutdown();
            }
        }

        #endregion
    }
}
